package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Employee;
import com.kaishengit.entity.IdeaComment;
import com.kaishengit.util.db.DBHelp;
import com.kaishengit.util.db.RowMapper;

public class IdeaCommentDao {
	private DBHelp<IdeaComment> db = new DBHelp<IdeaComment>();
	public List<IdeaComment> findByIdeaId(String id) {
		String sql ="select t_ideacomment.id,t_ideacomment.content,t_ideacomment.createtime,t_ideacomment.ideaid,employeeid,t_employee.username from t_ideacomment,t_employee where t_ideacomment.employeeid=t_employee.id and ideaid=? order by t_ideacomment.createtime desc";
		return db.executeQueryToList(sql, 
		  new RowMapper<IdeaComment>(){
			public IdeaComment mapRow(ResultSet rs) throws SQLException {
				IdeaComment ic = new IdeaComment();
				ic.setId(rs.getString("id"));
				ic.setContent(rs.getString("content"));
				ic.setCreatetime(rs.getString("createtime"));
				ic.setEmployeeid(rs.getString("employeeid"));
				ic.setIdeaid(rs.getString("ideaid"));
				
				Employee e = new Employee();
				e.setId(rs.getString("employeeid"));
				e.setUsername(rs.getString("username"));
				
				ic.setEmployee(e);
				
				return ic;
			}}, id);
		
	    }
	public void delIdeaById(String id) {
		String sql = "delete from t_ideacomment where id = ?";
		db.executeSQL(sql, id);
	}
	
}
